﻿
@{
    ViewData["Title"] = "Show";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>采购管理</title>
    <link href="~/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div class="layui-inline ">
        &nbsp;&nbsp;
        采购单号：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="procurementCode" id="procurementCode" />
        </div>&nbsp;&nbsp;
        产品编号：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="productCode" id="productCode" />
        </div>&nbsp;&nbsp;
        产品名称：
        <div class="layui-inline ">
            <input class="layui-input layui-input-inline" name="productName" id="productName" />
        </div>&nbsp;&nbsp;
        订单状态：
        <div class="layui-input-inline">
            <select name="state" id="state">
                <option value="">请选择</option>
                <option value="全部入库">全部入库</option>
                <option value="部分入库">部分入库</option>
                <option value="订单取消">订单取消</option>
                <option value="采购中">采购中</option>
            </select>
        </div>
        <br />
        &nbsp;&nbsp;&nbsp;
        <button type="button" id="btnSearch" class="layui-btn layui-btn-primary">查询</button>
        <button type="button" class="layui-btn  layui-btn-normal" onclick="add()">添加</button>
    </div>

    <table class="layui-hide" id="client" lay-filter="test">
    </table>

    <div id="demo-laypage-all"></div>
    <script type="text/html" id="barClient">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>

    <!-- HTML Content -->
    <script src="~/layui-v2.5.6/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
    <script>
        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer; //弹层
            var table = layui.table; //表格
            var laypage = layui.laypage;
            querylist = function () {
                var procurementCode = $("#procurementCode").val();
                var productCode = $("#productCode").val();
                var productName = $("#productName").val();
                var state = $("#state").val();
                //执行一个 table 实例
                table.render({
                    elem: '#client'
                    , height: 520
                    , url: '/Procurement/GetProcurement'// + name //数据接口
                    , where: {
                        procurementCode: procurementCode
                        , productCode: productCode
                        , productName: productName
                        , state: state
                    }
                    //, method: 'get'
                    , title: '采购管理'
                    , page: {
                        limit: 10,
                        limits: [10, 15, 20, 25],
                        prev:'上一页',
                        next:'下一页',
                        first:'首页',
                        last:'尾页'
                    }
                    , cols: [[ //表头
                        { type: 'checkbox', fixed: 'left' }//锁定第一列
                        , { field: 'ProcurementCode', title: '订单号', width: 150 }
                        , { field: 'ProductName', title: '产品名称', width: 150 }
                        , { field: 'ProductCode', title: '产品编号', width: 150 }
                        , { field: 'ProductSpecification', title: '产品规格', width: 150 }
                        , { field: 'Unit', title: '单位', width: 150 }
                        , { field: 'UnitPrice', title: '单价', width: 150 }
                        , { field: 'Quantity', title: '数量', width: 150 }
                        , {
                            title: '总额', width: 150, templet: function (row) {
                                var sum = row.UnitPrice * row.Quantity;
                                return sum;
                                //var tmpHtml = "<input /> <button onclick=\"delete(" + row.id + ")\">测试</button>";
                                //return tmpHtml;
                            }
                        }
                        , { field: 'SupplierCode', title: '供应商编号', width: 150 }
                        , { field: 'SupplierName', title: '供应商名称', width: 150 }
                        , { field: 'State', title: '状态', width: 150 }
                        , {
                            field: 'IsEntry', title: '是否入账', width: 150, templet: function (row) {
                                var tmpIsEntry = row.IsEntry == 1 ? "是" : "否";
                                return tmpIsEntry;
                                //var tmpHtml = "<input /> <button onclick=\"delete(" + row.id + ")\">测试</button>";
                                //return tmpHtml;
                            }
                        }
                        , { field: 'ReturnGood', title: '退货', width: 150 }
                        ,{
                            field: 'CreateDate', width: 150, title: '创建时间', templet: function (row) {
                                var DeliveryDate = row.CreateDate.split("T")[0]
                                return DeliveryDate;
                            }
                        }
                        , { fixed: 'right', width: 165, align: 'center', toolbar: '#barClient' }
                    ]],
                    request: {
                        pageName:'page',
                        limitName:'limit',
                    },
                    done: function (res) {
                        console.log(res);
                        return {
                            "code":res.code,
                            'count':res.count,
                            'data':res.data,
                        }
                        //表格绑定数据后的回调函数
                        layer.msg('权限展示完成！', {
                            icon: 1,
                            time: 1000
                        });
                    }
                });
            }

            querylist();

            $("#btnSearch").on("click", function () {
                querylist();
            })

            //监听 表行 工具栏事件
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'delete') {
                    layer.confirm('真的删除行么', function () {
                        //alert(data.Id);
                        console.log(data);
                        //obj.del(); //删除对应行（tr）的DOM结构
                        //layer.close(index);
                        //向服务端发送删除指令
                        // var arr = [];
                        // arr.push(data.Id);
                        // console.log(arr);
                        // var list = JSON.stringify(arr)
                        $.post("/Procurement/DeleteProcurement?id=" + data.Id,
                            res => {
                                console.log(res);
                                if (res) {
                                    console.log(res);
                                    layer.msg('删除采购成功', {
                                        icon: 1,
                                        time: 1000
                                    }, function () {
                                        querylist();
                                    });
                                }
                                else {
                                    layer.msg('删除采购失败！', {
                                        icon: 1,
                                        time: 1000
                                    });
                                }
                            }
                        )
                    });
                } else if (layEvent === 'edit') {
                    localStorage.setItem("updateProcurement", JSON.stringify(data));
                    window.location.href = "/Procurement/Update";
                }
            });
        });

        function add() {
            window.location.href = "/Procurement/Add";
        }
    </script>
</body>
</html>

